﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using Social.Twitter;
using SocialNetworks.Config;
using Twitterizer;
using Social.Facebook;
using Logic.SocialNetworks;

/// <summary>
/// Summary description for api
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class api : System.Web.Services.WebService {

    public api () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod()]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public Social.ContentServiceResponse<String> HelloWorld()
    {
        return new Social.ContentServiceResponse<String> { Message = "OK", ResultOption = Social.ServiceResultOptions.Success, Content = "Hellow World" };
    }

    [WebMethod()]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public Social.ContentServiceResponse<TwitterUserCollection> GetFollowersByID(int twitterID)
    {
        var twit = new TwitterAPI(new TwitterConfig());
        var followers = twit.GetFolowers(twitterID);
        return followers;
    }

    [WebMethod()]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public Social.ContentServiceResponse<TwitterUserCollection> GetFollowers(string twitterScreenName)
    {
        var twit = new TwitterAPI(new TwitterConfig());
        var followers = twit.GetFolowers(twitterScreenName);
        return followers;
    }

    [WebMethod()]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public Social.ContentServiceResponse<GraphApi.Page> GetPageByName(string pageName)
    {
        var page = GraphApi.GetPageByName(pageName); ;
        return page;
    }
    [WebMethod()]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public Social.ContentServiceResponse<GraphApi.Page> GetPageByID(long pageID)
    {
        var page = GraphApi.GetPageById(pageID); ;
        return page;
    }

    [WebMethod()]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public Object GetPageFans(long pageID)
    {
        var cc = new System.Net.CookieContainer();
        FbScraper.ScraperUtils.Login(cc, "lehmannds3@gmail.com", "1882,anc");
        FbScraper.PageScraper ps = new FbScraper.PageScraper();
        var fanStats = ps.GetPageFans(124385520934743, "http://www.facebook.com/pages/Interesting-trivia-from-Bil/124385520934743", cc);
        return new Social.ContentServiceResponse<Object> { Content = fanStats.Select(f => f.Value), Message = "OK", ResultOption = Social.ServiceResultOptions.Success };
    }

    [WebMethod()]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public Social.ContentServiceResponse<int> GetPageFansCount(long pageID)
    {
        var cc = new System.Net.CookieContainer();
        FbScraper.ScraperUtils.Login(cc, "lehmannds3@gmail.com", "1882,anc");
        FbScraper.PageScraper ps = new FbScraper.PageScraper();
        int num = ps.GetFansNum(161193133389, "http://www.facebook.com/cocacola?v=app_161193133389", cc);
        return new Social.ContentServiceResponse<int> { Content = num, Message = "OK", ResultOption = Social.ServiceResultOptions.Success };
    }

    
}
